** estimate effects by ability 

***Inputs: 
* $Data/normscore_IV60_ability.dta

***Outputs:
* $Results/residmem_eduthree_obs.png
* $Results/byability
* $Results/pvals_ability.dta
* $Results/resid_int.png
* $Results/resid_intgame.png
* $Results/resid_abovefiveplay.png

	
	
	use $Data/normscore_IV60_ability.dta, clear
	
	* discrete variable for three levels of education 
	
	gen educthree = 1 if education_level == 1 | education_level==2 | education_level == 3 | education_level== 8
	replace educthree = 2 if education_level == 4 
	replace educthree = 3 if education_level == 5 | education_level == 6 | education_level == 7
	
	label define educthree 1 "< College" 2 "Bachelor" 3 "Post-graduate"
	label values educthree educthree
	
	
	reg residmem i.educthree // omitted category is high school/ some high school 
	eststo resid_educthree
	
	
		gen ones = 1
	
	
	
	collapse (sum) Obs = ones , by(educthree)
		
		label variable Obs "Observations (000s)"
	
	replace Obs = Obs/1000
	
	
	coefplot 	(resid_educthree, keep(1.educthree) ciopts(recast(rcap) lcolor(red)) mcolor(red) ) ///
	(resid_educthree, keep(2.educthree) ciopts(recast(rcap) lcolor(orange)) mcolor(orange)) ///
	(resid_educthree, keep(3.educthree) ciopts(recast(rcap) lcolor(gold)) mcolor(gold) ) ///
	, vertical levels(95) yline(0)  nooffsets  legend(off) xlabel(, angle(60))  msymbol(D) omitted baselevels yaxis(2) ytitle(Difference in score relative to < College, axis(2))
		
		
		addplot: bar Obs educthree if educthree ==1, yaxis(1) bcolor(red%20) yscale(range(0(500)2000) axis(1)) ylabel(0(500)2000, axis(1))
		addplot: bar Obs educthree if educthree ==2, yaxis(1) bcolor(orange%20) yscale(range(0(500)2000) axis(1)) ylabel(0(500)2000, axis(1))
		addplot: bar Obs educthree if educthree ==3, yaxis(1) bcolor(gold%20) yscale(range(0(500)2000) axis(1)) ylabel(0(500)2000, axis(1)) ytitle(Observations (000s), axis(1)) xlabel(1 "< College" 2 "Bachelor" 3 "Post-graduate")
		
		
	graph export  $Results/residmem_eduthree_obs.png, replace

	
		
	

		
		
	use $Data/normscore_IV60_ability.dta, clear

		


ivreghdfe norm_score (c.highpm#i.quinresid =c.maxzipwind#i.quinresid ) weighted_wind_speed weighted_precipitation , absorb(anon_id monthyear cut_temp) cluster(anon_id monthyear)


eststo residint


estimates save $Results/byability, replace

	regsave 1b.quinresid#c.highpm 2.quinresid#c.highpm 3.quinresid#c.highpm 4.quinresid#c.highpm 5.quinresid#c.highpm using $Results/pvals_ability.dta , pval

	




	
		coefplot (residint, keep(1.quinresid#c.highpm) ciopts(recast(rcap) lcolor(red%30))  mcolor(red) msymbol(D) msize(large) ) ///
	(residint, keep(2.quinresid#c.highpm)   ciopts(recast(rcap) lcolor(orange%30))  mcolor(orange) msymbol(D) msize(large) ) ///
	(residint, keep(3.quinresid#c.highpm)  ciopts(recast(rcap) lcolor(gold%30)) mcolor(gold) msymbol(D) msize(large)  )  ///
	(residint, keep(4.quinresid#c.highpm)  ciopts(recast(rcap) lcolor(green%30)) mcolor(green) msymbol(D) msize(large) ) ///
	(residint, keep(5.quinresid#c.highpm)  ciopts(recast(rcap) lcolor(blue%30)) mcolor(blue) msymbol(D) msize(large) ) ,  /// 
	drop(weighted*)  ///
			     vertical levels(95) yline(0)   legend(off)      ///
				 coeflabels(1.quinresid#c.highpm = "Quintile 1" ///
                2.quinresid#c.highpm = "Quintile 2" ///
			  3.quinresid#c.highpm = "Quintile 3" ///
			   4.quinresid#c.highpm = "Quintile 4" ///
			  5.quinresid#c.highpm = "Quintile 5" ///
			   ) nooffsets omitted baselevels
	
	graph export $Results/resid_int.png, replace
	
	
	
	
	


ivreghdfe norm_score (c.highpm#i.quinresid =c.maxzipwind#i.quinresid ) weighted_wind_speed weighted_precipitation , absorb(anon_id monthyear cut_temp gamenum) cluster(anon_id monthyear)


eststo residintgame
	
	
	
	
	
	
		coefplot (residintgame, keep(1.quinresid#c.highpm) ciopts(recast(rcap) lcolor(red%30))  mcolor(red) msymbol(D) msize(large) ) ///
	(residintgame, keep(2.quinresid#c.highpm)   ciopts(recast(rcap) lcolor(orange%30))  mcolor(orange) msymbol(D) msize(large) ) ///
	(residintgame, keep(3.quinresid#c.highpm)  ciopts(recast(rcap) lcolor(gold%30)) mcolor(gold) msymbol(D) msize(large)  )  ///
	(residintgame, keep(4.quinresid#c.highpm)  ciopts(recast(rcap) lcolor(green%30)) mcolor(green) msymbol(D) msize(large) ) ///
	(residintgame, keep(5.quinresid#c.highpm)  ciopts(recast(rcap) lcolor(blue%30)) mcolor(blue) msymbol(D) msize(large) ) ,  /// 
	drop(weighted*)  ///
			     vertical levels(95) yline(0)   legend(off)      ///
				 coeflabels(1.quinresid#c.highpm = "Quintile 1" ///
                2.quinresid#c.highpm = "Quintile 2" ///
			  3.quinresid#c.highpm = "Quintile 3" ///
			   4.quinresid#c.highpm = "Quintile 4" ///
			  5.quinresid#c.highpm = "Quintile 5" ///
			   ) nooffsets omitted baselevels yscale(range(-2 2)) ylabel(-2(1)2)
	
	graph export $Results/resid_intgame.png, replace
	
	
	
	
	
	
	
		gen above5play = nth_play >= 5 & nth_play<.

	


ivreghdfe norm_score (c.highpm#i.quinresid =c.maxzipwind#i.quinresid ) weighted_wind_speed weighted_precipitation , absorb(anon_id monthyear cut_temp above5play) cluster(anon_id monthyear)


eststo residintabove5




	
	
	
		coefplot (residintabove5, keep(1.quinresid#c.highpm) ciopts(recast(rcap) lcolor(red%30))  mcolor(red) msymbol(D) msize(large) ) ///
	(residintabove5, keep(2.quinresid#c.highpm)   ciopts(recast(rcap) lcolor(orange%30))  mcolor(orange) msymbol(D) msize(large) ) ///
	(residintabove5, keep(3.quinresid#c.highpm)  ciopts(recast(rcap) lcolor(gold%30)) mcolor(gold) msymbol(D) msize(large)  )  ///
	(residintabove5, keep(4.quinresid#c.highpm)  ciopts(recast(rcap) lcolor(green%30)) mcolor(green) msymbol(D) msize(large) ) ///
	(residintabove5, keep(5.quinresid#c.highpm)  ciopts(recast(rcap) lcolor(blue%30)) mcolor(blue) msymbol(D) msize(large) ) ,  /// 
	drop(weighted*)  ///
			     vertical levels(95) yline(0)   legend(off)      ///
				 coeflabels(1.quinresid#c.highpm = "Quintile 1" ///
                2.quinresid#c.highpm = "Quintile 2" ///
			  3.quinresid#c.highpm = "Quintile 3" ///
			   4.quinresid#c.highpm = "Quintile 4" ///
			  5.quinresid#c.highpm = "Quintile 5" ///
			   ) nooffsets omitted baselevels
	
	graph export $Results/resid_abovefiveplay.png, replace
	
	
	
	
	
	

	

	
	
